import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { FetchService } from '../../../core/net/fetch.service';

@Component({
  selector: 'app-equipment-status',
  templateUrl: './equipment-status.component.html',
  styleUrls: ['./equipment-status.component.scss']
})
export class EquipmentStatusComponent implements OnInit {
    searchForm: FormGroup;
    tableData = [];
    searchForm1: FormGroup; //  大闸
    tableData1 = [];
    tableWidthConfig = ['75px', '220px', '150px', '150px', '150px', '150px', '150px'];
    pageNum = 1;
    pageSize = 10;
    total: number;
    loading = false;
    pageNum1 = 1;
    pageSize1 = 10;
    loading1 = false;
    total1: number;

    constructor(private fb: FormBuilder,
                private fetchService: FetchService) {
        this.searchForm = this.fb.group({
            watergateCode: [null]
        });
        this.searchForm1 = this.fb.group({
            watergateCode: []
        });
    }

    ngOnInit(): void {
        this.queryInfo();
    }
    getData(e): void {
        if (e === 0) {
            this.queryInfo(true);
        } else {
            this.queryGateInfo();
        }
    }
    queryInfo(reset: boolean = false): void {
        if (reset) {
            this.pageNum = 1;
        }
        this.loading = true;
        const params = {
            ...this.searchForm.value,
            pageNum: this.pageNum,
            pageSize: this.pageSize
        };
        this.fetchService.post('base/wrsBrwaterDam/queryDamInfoList', params).subscribe(res => {
            this.tableData = res['list'];
            this.total = res['total'];
            this.loading = false;
        });
    }
    queryGateInfo(): void {
        this.loading1 = true;
        this.fetchService.post<Array<any>>('wrs/wrsBawaterGate/gateInfo', {
            // apicode: '36',
            ...this.searchForm1.value
        }).subscribe(res => {
            this.tableData1 = res;
            this.loading1 = false;
            this.total1 = res.length;
        });
    }
}
